Wiki

Clone wiki

Etz.Api / Bearer Tokens

#Bearer Tokens#

Note: Before you can create a token you will need a Goowid Client Id and Client Secret. Please contact Support at support@etztec.com to receive this.

In order to access our API, you will need a valid token.

Sample code for .NET can be found in the source code here.

Below are snippets of the main part of the code that makes the request to Goowid and returns a token id string.

Sample C# code

#!c#



using System;
using System.Configuration;
using System.Net.Http;
using System.Threading.Tasks;
using IdentityModel.Client;

namespace Etz.Api.Sample.Console
{
    public class GoowidClient : IDisposable
    {
        private HttpClient tokenClient { get; set; }
        private DiscoveryResponse disco { get; set; }

        public GoowidClient()
        {
            SetUpClient();
        }

        private void SetUpClient()
        {
            tokenClient = new HttpClient();
            disco = tokenClient.GetDiscoveryDocumentAsync(ConfigurationManager.AppSettings["Goowid:Domain"]).Result;

            if (disco.IsError) throw new Exception(disco.Error);

        }

        public void Dispose()
        {
            tokenClient?.Dispose();
        }

        public async Task<TokenResponse> AuthenticateUser(string username, string password)
        {
            if (tokenClient == null)
                tokenClient = new HttpClient();

            var response = await tokenClient.RequestPasswordTokenAsync(new PasswordTokenRequest
            {
                Address = disco.TokenEndpoint,

                ClientId = ConfigurationManager.AppSettings["Goowid:ApiClientId"],
                ClientSecret = ConfigurationManager.AppSettings["Goowid:ApiClientSecret"],

                UserName = username,
                Password = password
            });

            return response;
        }
    }
}

The GetToken method would return a valid token that you can use to call operations on the Etz API.

Updated